﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Thanhlichtek.BEF.Fix
{
    public static class Utils
    {
        public static string InvalidCharacters = @"!#$%&'*+-/=?^_`{|}~(),:;<>[\]><";
        public static string FixEmailAddress(string emailAddress)
        {
            if (emailAddress == null)
            {
                return null;
            }
            string result = emailAddress;
            //remove spaces
            result = result.Replace(" ", string.Empty);
            //remove special characters
            var invalidCharactersArray = InvalidCharacters.ToCharArray();
            foreach (var badChar in invalidCharactersArray)
            {
                if (result.Contains(badChar))
                {
                    result = result.Replace(badChar.ToString(), string.Empty);
                }
            }
            //remove @@
            while (result.Contains("@@"))
            {
                result = result.Replace("@@", "@");
            }
            return result;
        }
    }
}
